--
-- Author: shunguo.chen
-- Date: 2018-10-10 14:41:55
--
-- LotteryInfo 抽奖信息

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	if data then
		self:init(data)
	end
end


-- message TenRand
-- {
-- 	int32 activityIdx = 1 ;			//抽奖编号
-- 	pb_loot.Loot button1Cost =2;	//按钮1消耗
-- 	pb_loot.Loot button2Cost =3; 	//按钮2消耗
-- 	int64 nextFreeUnix =4; 		//下一次免费的时间 默认只在按钮1生效
-- 	int32 nextGiftCount =5;		//下一次 保底奖励次数(还要抽几次)
-- }
function ClassRef:init(data)
	self.activityIdx = data.activityIdx

	if data.button1Cost then
		self.button1Cost = UD:parseLootToBagItem(data.button1Cost)
	end

	if data.button2Cost then
		self.button2Cost = UD:parseLootToBagItem(data.button2Cost)
	end

	self.nextFreeUnix = data.nextFreeUnix
	self.nextGiftCount = data.nextGiftCount
end

function ClassRef:getHaveNum()
	return UD:getItemAmountByTid(self.button1Cost.tid)
end

function ClassRef:getFreeTime()
	local serverTime = math.floor(app:getServerTime())
	if self.nextFreeUnix > serverTime then
		return self.nextFreeUnix - serverTime
	end
	return 0
end

return ClassRef